package com.haizhi.crm.sys.configure.model;

import com.haizhi.crm.common.constant.CrmConstant;
import com.haizhi.crm.common.model.BaseDo;
import com.haizhi.crm.common.util.CommonUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Created by caochao on 2018/05/31.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "ts_user_module_setting" )
public class UserModuleSettingDo extends BaseDo {

    private Long settingId;
    private Long userModuleId;
    private String settingValue;


    public static UserModuleSettingDo fromVo(UserModuleSettingItemVo vo, Long userModuleId) {
        ModuleSettingVo moduleSettingVo = vo.getSettingItem();
        UserModuleSettingDo userModuleSettingDo = UserModuleSettingDo.builder().settingId(moduleSettingVo.getSettingId()).userModuleId(userModuleId).settingValue(vo.getSettingValue()).build();
        userModuleSettingDo.setEnabledFlag(CrmConstant.ENABLE_FLAG);
        userModuleSettingDo.setCreatedById(CommonUtils.getUserID());
        userModuleSettingDo.setUpdateById(CommonUtils.getUserID());
        return userModuleSettingDo;
    }
}
